﻿
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using TV4Home.Server.TVEInteractionLibrary;
using TV4Home.Server.TVEInteractionLibrary.Interfaces;
using TV4Home.WebInterface.UI.Code;

namespace TV4Home.WebInterface.UI
{
    public partial class Recordings : PageBase
    {
        protected void Page_Load(object sender, EventArgs e)
        {
        }

        public override void UpdateUI()
        {
            this.DataList1.DataSource = WebService.TV4HomeWebService.ServiceInstance.GetSchedules();
            this.DataList1.DataBind();
        }

        protected void DataList1_ItemCommand(object source, DataListCommandEventArgs e)
        {
            string cmd = ((LinkButton)e.CommandSource).CommandName;

            if (cmd == "select")
                this.DataList1.SelectedIndex = e.Item.ItemIndex;

            this.DataList1.DataBind();
        }

        protected void DataList1_ItemDataBound(object sender, DataListItemEventArgs e)
        {
            if (e.Item.ItemType != ListItemType.SelectedItem)
            {
                WebSchedule schedule = (WebSchedule)e.Item.DataItem;

                Label lblProgramName = (Label)e.Item.FindControl("lblProgramName");
                Label lblDate = (Label)e.Item.FindControl("lblDate");
                Label lblChannel = (Label)e.Item.FindControl("lblChannel");
                Label lblStartTime = (Label)e.Item.FindControl("lblStartTime");
                Label lblEndTime = (Label)e.Item.FindControl("lblEndTime");

                lblProgramName.Text = schedule.ProgramName;
                lblDate.Text = schedule.StartTime.ToLongDateString();
                lblChannel.Text = WebService.TV4HomeWebService.ServiceInstance.GetChannelBasicById(schedule.IdChannel).DisplayName;
                lblStartTime.Text = schedule.StartTime.ToShortTimeString();
                lblEndTime.Text = schedule.EndTime.ToShortTimeString();
            }
        }
    }
}
